package com.esri.core.symbol;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.Log;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.Polyline;
import com.esri.core.internal.util.d;
import com.esri.core.internal.util.h;
import com.esri.core.io.EsriServiceException;
import com.github.mikephil.charting.utils.Utils;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;

/* loaded from: classes.dex */
public class SymbolHelper implements SymbolFactory {
    static final int a = 48;

    static native void nativeCreateSymbolImage(String str, int i, Bitmap bitmap, byte[] bArr);

    static native void nativeCreateSymbolImages(int i, String[] strArr, Object[] objArr, int i2, int i3, int i4, Bitmap[] bitmapArr);

    static {
        h.a(new SymbolHelper());
    }

    public static Symbol createSymbol(JsonParser jsonParser) {
        String textValue;
        Symbol multiLayerSymbol;
        try {
            if (!d.c(jsonParser)) {
                throw new EsriServiceException("This symbol cannot be parsed.");
            }
            JsonNode b = d.b(jsonParser);
            JsonNode jsonNode = b.get("type");
            if (jsonNode == null || (textValue = jsonNode.getTextValue()) == null) {
                return null;
            }
            if (PictureMarkerSymbol.TYPE.equals(textValue)) {
                multiLayerSymbol = new PictureMarkerSymbol(b);
            } else if (SimpleFillSymbol.TYPE.equals(textValue)) {
                multiLayerSymbol = new SimpleFillSymbol(b);
            } else if (SimpleLineSymbol.TYPE.equals(textValue)) {
                multiLayerSymbol = new SimpleLineSymbol(b);
            } else if (SimpleMarkerSymbol.TYPE.equals(textValue)) {
                multiLayerSymbol = new SimpleMarkerSymbol(b);
            } else if (TextSymbol.TYPE.equals(textValue)) {
                multiLayerSymbol = new TextSymbol(b);
            } else if ("esriCS".equals(textValue)) {
                multiLayerSymbol = new CompositeSymbol(b);
            } else if (!textValue.startsWith(MultiLayerSymbol.TYPE_PREFIX)) {
                return null;
            } else {
                multiLayerSymbol = new MultiLayerSymbol(b);
            }
            return multiLayerSymbol;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override // com.esri.core.symbol.SymbolFactory
    public Symbol getSymbol(JsonParser jsonParser) {
        return createSymbol(jsonParser);
    }

    public static Bitmap getLegendImage(Symbol symbol, int i, int i2) {
        if (symbol == null || i < 1 || i2 < 1) {
            return null;
        }
        return getLegendImage(symbol, a(symbol, i, i2), i, i2, 0);
    }

    public static Bitmap getLegendImage(Symbol symbol, Geometry geometry, int i, int i2, int i3) {
        Bitmap bitmap = null;
        if (i >= 1 && i2 >= 1 && geometry != null && symbol != null) {
            bitmap = Bitmap.createBitmap(i, i2, Bitmap.Config.ARGB_8888);
            try {
                nativeCreateSymbolImage(symbol.toJson(), Color.argb(Color.alpha(i3), Color.blue(i3), Color.green(i3), Color.red(i3)), bitmap, GeometryEngine.geometryToEsriShape(geometry));
            } catch (Exception e) {
                Log.e(com.esri.core.internal.a.a, "Can not create the swatch for the symbol.", e);
                throw new IllegalArgumentException(e);
            }
        }
        return bitmap;
    }

    private static Geometry.Type a(Symbol symbol) {
        if (symbol instanceof MarkerSymbol) {
            return Geometry.Type.POINT;
        }
        if (symbol instanceof LineSymbol) {
            return Geometry.Type.LINE;
        }
        if (symbol instanceof FillSymbol) {
            return Geometry.Type.POLYGON;
        }
        return Geometry.Type.UNKNOWN;
    }

    private static Geometry a(Symbol symbol, int i, int i2) {
        int i3 = AnonymousClass1.a[a(symbol).ordinal()];
        if (i3 == 1 || i3 == 2 || i3 == 3) {
            Polygon polygon = new Polygon();
            Polygon polygon2 = polygon;
            polygon2.startPath(Utils.DOUBLE_EPSILON, Utils.DOUBLE_EPSILON);
            double d = i2;
            polygon2.lineTo(Utils.DOUBLE_EPSILON, d);
            double d2 = i;
            polygon2.lineTo(d2, d);
            polygon2.lineTo(d2, Utils.DOUBLE_EPSILON);
            polygon2.lineTo(Utils.DOUBLE_EPSILON, Utils.DOUBLE_EPSILON);
            return polygon;
        } else if (i3 == 4 || i3 == 5) {
            Polyline polyline = new Polyline();
            Polyline polyline2 = polyline;
            polyline2.startPath(Utils.DOUBLE_EPSILON, Utils.DOUBLE_EPSILON);
            polyline2.lineTo(i, i2);
            return polyline;
        } else {
            if (symbol instanceof MarkerSymbol) {
                if (i2 <= 0) {
                    i2 = 48;
                }
                if (i <= 0) {
                    i = 48;
                }
            }
            if (symbol instanceof TextSymbol) {
                ((TextSymbol) symbol).setText("abc");
                return new Point(Utils.DOUBLE_EPSILON, Utils.DOUBLE_EPSILON);
            }
            return new Point(i / 2, i2 / 2);
        }
    }

    /* renamed from: com.esri.core.symbol.SymbolHelper$1 */
    /* loaded from: classes.dex */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[Geometry.Type.values().length];
            a = iArr;
            try {
                iArr[Geometry.Type.ENVELOPE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[Geometry.Type.MULTIPOINT.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[Geometry.Type.POLYGON.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                a[Geometry.Type.LINE.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                a[Geometry.Type.POLYLINE.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                a[Geometry.Type.POINT.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
        }
    }

    public static Bitmap[] getLegendImages(Symbol[] symbolArr, int i, int i2) {
        return getLegendImages(symbolArr, null, i, i2, 0);
    }

    public static Bitmap[] getLegendImages(Symbol[] symbolArr, Geometry[] geometryArr, int i, int i2, int i3) {
        Bitmap[] bitmapArr = new Bitmap[0];
        if (symbolArr != null) {
            bitmapArr = new Bitmap[symbolArr.length];
            int length = symbolArr.length;
            String[] strArr = new String[length];
            Object[] objArr = new Object[symbolArr.length];
            if (geometryArr == null) {
                geometryArr = a(symbolArr, i, i2);
            }
            for (int i4 = 0; i4 < symbolArr.length; i4++) {
                try {
                    strArr[i4] = symbolArr[i4].toJson();
                    objArr[i4] = GeometryEngine.geometryToEsriShape(geometryArr[i4]);
                    bitmapArr[i4] = Bitmap.createBitmap(i, i2, Bitmap.Config.ARGB_8888);
                } catch (Exception e) {
                    Log.e(com.esri.core.internal.a.a, "Can not create the swatch for the symbol.", e);
                    throw new IllegalArgumentException(e);
                }
            }
            nativeCreateSymbolImages(length, strArr, objArr, i, i2, Color.argb(Color.alpha(i3), Color.blue(i3), Color.green(i3), Color.red(i3)), bitmapArr);
        }
        return bitmapArr;
    }

    static Geometry[] a(Symbol[] symbolArr, int i, int i2) {
        Geometry[] geometryArr = new Geometry[symbolArr.length];
        for (int i3 = 0; i3 < symbolArr.length; i3++) {
            geometryArr[i3] = a(symbolArr[i3], i, i2);
        }
        return geometryArr;
    }

    public static final Symbol parseSymbol(JsonNode jsonNode) throws Exception {
        JsonNode jsonNode2 = jsonNode != null ? jsonNode.get("type") : null;
        if (jsonNode2 != null) {
            String textValue = jsonNode2.getTextValue();
            if (TextSymbol.TYPE.equals(textValue)) {
                return new TextSymbol(jsonNode);
            }
            if (SimpleMarkerSymbol.TYPE.equals(textValue)) {
                return new SimpleMarkerSymbol(jsonNode);
            }
            if (SimpleLineSymbol.TYPE.equals(textValue)) {
                return new SimpleLineSymbol(jsonNode);
            }
            if (SimpleFillSymbol.TYPE.equals(textValue)) {
                return new SimpleFillSymbol(jsonNode);
            }
            if (PictureMarkerSymbol.TYPE.equals(textValue)) {
                return new PictureMarkerSymbol(jsonNode);
            }
            if (PictureFillSymbol.TYPE.equals(textValue)) {
                return new PictureFillSymbol(jsonNode);
            }
            if (textValue == null || !textValue.startsWith(MultiLayerSymbol.TYPE_PREFIX)) {
                return null;
            }
            return new MultiLayerSymbol(jsonNode);
        }
        return null;
    }
}
